package com.hs.pre.module.tree;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hs.core.action.BaseAction;
import com.hs.core.db.DBOperator;
import com.hs.core.db.DatabaseConnection;
import com.hs.log.HsLogger;

 

public class IndexLeftTreeAction extends BaseAction{
private static final HsLogger logger = HsLogger.getLogger(IndexLeftTreeAction.class.getName());
public ActionForward execute(ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response) throws Exception {
	String action = request.getParameter("action");
	if("index".equals(action)){
		String menuId = request.getParameter("menuId");
		String sql = "SELECT MENUID,MENUNAME,MENUREMARK from app.HS_MENUINFO WHERE MENUPARENTID=?" ;
//		DatabaseConnection.
		DBOperator dbo = DatabaseConnection.getDBOperator(); 
		List dataList = dbo.select(sql, new Object[]{menuId}); 
		StringBuffer buffer = new StringBuffer();
		buffer.append("[");
		for(int i = 0;i<dataList.size();i++){
			Map m = (Map)dataList.get(i);
			String id = m.get("MENUID")+"";   
			buffer.append("{text:'");
			buffer.append(m.get("MENUNAME"));
			buffer.append("',");
			buffer.append("qtip:'"+m.get("MENUNAME")+"',id:'"+id+"'");
			buffer.append(",model:'client'");
			buffer.append(",leaf:'true',"); 
			buffer.append("icon:'',");
			buffer.append("action:'"+m.get("MENUREMARK")+"'");
			buffer.append("},");
	//		buffer.append(m.get("UP_BOOK_ID"));
	//		buffer.append(",");
	//		buffer.append(m.get("BOOK_TITLE"));
	//		buffer.append(","); 
	//		buffer.append(request.getContextPath()+"/ebook/control.do?moduleId="+m.get("MODULE_ID")+"&id="+id);
	//		buffer.append("#"); 
		}
		buffer.append("]"); 
		response.setCharacterEncoding("UTF-8");
		try {
			PrintWriter w = response.getWriter();
			w.append(buffer); 
			logger.info(buffer.toString());
			w.flush();
			w.close();
		} catch (IOException e) {
			 
			e.printStackTrace();
		}
	}
	return null;
}

}
